package org.agony2d.gpu.core.animation {
	import org.agony2d.debug.Logger;
	import org.agony2d.core.agony_internal;
	
	use namespace agony_internal;
	
public class FrameClip {
  
    public function FrameClip( clipData:String, frameRate:int ) {
		this.doParseClipData(clipData)
		this.roundTime = 1000.0 / frameRate
	}
	
	
	agony_internal var frames:Vector.<int>
	agony_internal var totalFrames:int
	agony_internal var roundTime:Number
	
	
	[Inline]
	final agony_internal function doParseClipData( data:String ) : void {
		var AY:Array
		var i:int, l:int
		
		this.frames = new <int>[]
		if (data.indexOf(",") != -1) {
			AY = data.split(",")
			l = AY.length
			while (i < l) {
				data = AY[i++]
				this.doParseClipDataByDetail(data)
			}
		}
		else {
			this.doParseClipDataByDetail(data)
		}
	}
	
	[Inline]
	final agony_internal function doParseClipDataByDetail( data:String ) : void {
		var AY:Array
		var i:int, l:int, num_A:int, num_B:int
		
		if (!isNaN(Number(data)) && data != "") {
			this.frames[this.totalFrames++] = int(data)
		}
		else if (data.indexOf("-") != -1) {
			AY = data.split("-")
			num_A = int(AY[0])
			num_B = int(AY[1])
			if (num_A < num_B) {
				while (num_A <= num_B) {
					this.frames[this.totalFrames++] = num_A++
				}
			}
			else {
				while (num_A >= num_B) {
					this.frames[this.totalFrames++] = num_A--
				}
			}
		}
		else if (data.indexOf("*") != -1) {
			AY = data.split("*")
			num_A = AY[0]
			l = AY[1]
			while (--l > -1) {
				this.frames[this.totalFrames++] = num_A
			}
		}
		else {
			Logger.reportError(this, "doParseClipDataByDetail", "error clip dataclip ( " + data + " )...!!")
		}
	}
}
}